<template>
  <div>
    <van-cell-group border>
      <van-field
        v-model="tel"
        label="手机号"
        placeholder="请输入手机号.."
        autofocus
      />
    </van-cell-group>
    <div class="loginBtn">
      <van-button type="danger" round block :disabled="flag" @click="next"
        >下一步</van-button
      >
    </div>
  </div>
</template>

<script>
import Vue from 'vue';
import {  CellGroup,Button,Dialog } from 'vant';

Vue.use(CellGroup);
Vue.use(Button);
Vue.use(Dialog);
import { doCheckPhone } from "../../api/user";
export default {
data () {
    return {
        tel:'',
        //flag:true
    }
},
computed: {
    flag(){
        //满足输入的内容满足手机号的正则规则
        if(/^1[3-9]\d{9}$/.test(this.tel)){
            return false;
        }else{
            return true
        }
    }
},
methods:{
    next(){
        //验证你的tel是否可以注册
        doCheckPhone({tel:this.tel}).then((res)=>{
            //console.log(res.data.code);
            switch (res.data.code) {
                case '10005':
                   Dialog.confirm({

                    message: '用户名已存在，是否去登录',
                    })
                    .then(() => {
                        // on confirm
                        this.$router.back()
                    })
                   
                    break;
             case '200':
                localStorage.setItem("tel",this.tel)
                this.$router.push("/register/two")
                break;
                default:
                    break;
            }
        })
    }
}
}
</script>

<style scoped>
.loginBtn {
  width: 80%;
  margin: 20px auto;
}
</style>